﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media;

namespace Endos.Wodice
{
    public partial class DiceControl : UserControl
    {
        private readonly static SolidColorBrush colorDefault;
        private readonly static SolidColorBrush colorSuccess;
        private readonly static SolidColorBrush colorFailure;
        private readonly static SolidColorBrush colorInitiative;

        static DiceControl()
        {
            colorDefault = new SolidColorBrush(Color.FromArgb(100, 0, 0, 0));
            colorSuccess = new SolidColorBrush(Color.FromArgb(100, 0, 255, 0));
            colorFailure = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0));
            colorInitiative = new SolidColorBrush(Color.FromArgb(100, 0, 0, 255));
        }

        private void Initialize()
        {
            InitializeComponent();
            textBlockTime.Text = DateTime.Now.ToString("hh:mm:ss.f");
        }

        public DiceControl(int initiative, int result)
            : base()
        {
            Initialize();
            rectangle.Fill = colorInitiative;
            textbBlockAmountSuccess.Text = (initiative + result).ToString();
            textBlockDescription.Text = string.Format("{0} ( + {1} )", initiative, result);
        }

        public DiceControl(IEnumerable<int> dices, int amountDices, int? amountSuccess)
            : base()
        {
            Initialize();
            if (amountSuccess.HasValue)
            {
                rectangle.Fill = amountSuccess.Value > 0 ? colorSuccess : colorDefault;
                textbBlockAmountSuccess.Text = amountSuccess.Value.ToString();
            }
            else
            {
                rectangle.Fill = colorFailure;
                textbBlockAmountSuccess.Text = "F. Crítica";
            }

            textBlockAmountDices.Text = amountDices.ToString();
            textBlockDescription.Text = string.Format("{0}.", string.Join(", ", dices));
        }
    }
}
